home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 37.3 KB | 1,406 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWDesc.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FWDESC_H
- #include "FWDesc.h"
- #endif
-
- #ifndef FWSCPCAL_H
- #include "FWScpCal.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWBARRAY_H
- #include "FWBArray.h"
- #endif
-
- #ifndef FWCOLOR_H
- #include "FWColor.h"
- #endif
-
- #ifndef FWRECT_H
- #include "FWRect.h"
- #endif
-
- // ----- Foundation Layer -----
-
- #ifndef FWEXCLIB_H
- #include "FWExcLib.h"
- #endif
-
- #ifndef FWMEMHLP_H
- #include "FWMemHlp.h"
- #endif
-
- #ifndef FWMEMMGR_H
- #include "FWMemMgr.h"
- #endif
-
- #ifndef FWPSTR_H
- #include "FWPStr.h"
- #endif
-
- #ifndef FWSOMENV_H
- #include "FWSOMEnv.h"
- #endif
-
- // ----- Macintosh Includes -----
-
- #ifndef __ASREGISTRY__
- #include <ASRegistry.h>
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODObjectSpec_xh
- #include <ODObjSpc.xh>
- #endif
-
- //========================================================================================
- // Runtime Information
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwsemevt2
- #endif
-
- FW_DEFINE_AUTO(FW_CDesc)
-
- //========================================================================================
- // CLASS FW_CDesc
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::FW_CDesc
- //----------------------------------------------------------------------------------------
-
- FW_CDesc::FW_CDesc() :
- fOwnODDesc(TRUE),
- fODDesc(NULL),
- fRealPlatformDesc(TRUE),
- fDataState(FW_kODDataIsStale),
- fODDescType(typeWildCard),
- fODDescTypeValid(FALSE)
- {
- fPlatformDesc.descriptorType = typeNull;
- fPlatformDesc.dataHandle = NULL;
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::FW_CDesc
- //----------------------------------------------------------------------------------------
-
- FW_CDesc::FW_CDesc(const FW_CDesc& copyDesc) :
- fOwnODDesc(TRUE),
- fODDesc(NULL),
- fRealPlatformDesc(TRUE),
- fDataState(FW_kODDataIsStale),
- fODDescType(typeWildCard),
- fODDescTypeValid(FALSE)
- {
- fPlatformDesc.descriptorType = typeNull;
- fPlatformDesc.dataHandle = NULL;
-
- ::AEDuplicateDesc(copyDesc, *this);
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::FW_CDesc
- //----------------------------------------------------------------------------------------
-
- FW_CDesc::FW_CDesc(ODDesc* odDesc) :
- fOwnODDesc(FALSE),
- fODDesc(odDesc),
- fRealPlatformDesc(FALSE),
- fDataState(FW_kPlatformDataIsStale),
- fODDescType(typeWildCard),
- fODDescTypeValid(FALSE)
- {
- fPlatformDesc.descriptorType = typeNull;
- fPlatformDesc.dataHandle = NULL;
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::~FW_CDesc
- //----------------------------------------------------------------------------------------
-
- FW_CDesc::~FW_CDesc()
- {
- FW_START_DESTRUCTOR
- PrivDispose();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::Clear
- //----------------------------------------------------------------------------------------
-
- void FW_CDesc::Clear()
- {
- PrivFlushPlatformData();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::CoerceInPlace
- //----------------------------------------------------------------------------------------
-
- void FW_CDesc::CoerceInPlace(ODDescType toType)
- {
-
- if (DescriptorType() != toType)
- Coerce(toType, *this);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::Coerce
- //----------------------------------------------------------------------------------------
-
- void FW_CDesc::Coerce(ODDescType toType, FW_CDesc& coercedDesc) const
- {
- FW_Handled handled = FW_CDescCoercionCallbacks::InvokeHandler(*this, toType, coercedDesc);
-
- if (handled == FW_kNotHandled)
- FW_FailOnError(::AECoerceDesc(*this, toType, coercedDesc));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::CreateSimple
- //----------------------------------------------------------------------------------------
-
- void FW_CDesc::CreateSimple(ODDescType dataType, const void* dataPtr, Size dataSize)
- {
- FW_ASSERT(fPlatformDesc.descriptorType == typeNull);
- FW_FailOnError(::AECreateDesc(dataType, dataPtr, dataSize, *this));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::CreateList
- //----------------------------------------------------------------------------------------
-
- void FW_CDesc::CreateList(void* commonDataPtr, Size commonDataSize)
- {
- FW_ASSERT(fPlatformDesc.descriptorType == typeNull);
- FW_FailOnError(::AECreateList(commonDataPtr, commonDataSize, FALSE, *this));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::CreateRecord
- //----------------------------------------------------------------------------------------
-
- void FW_CDesc::CreateRecord(void* commonDataPtr, Size commonDataSize)
- {
- FW_ASSERT(fPlatformDesc.descriptorType == typeNull);
- FW_FailOnError(::AECreateList(commonDataPtr, commonDataSize, TRUE, *this));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::DescriptorType
- //----------------------------------------------------------------------------------------
-
- ODDescType FW_CDesc::DescriptorType() const
- {
- ODDescType descriptorType;
-
- if (fODDesc && fDataState == FW_kPlatformDataIsStale)
- {
- if (!fODDescTypeValid)
- {
- FW_CDesc* mutableDesc = (FW_CDesc*)this;
-
- FW_SOMEnvironment ev;
- mutableDesc->fODDescType = fODDesc->GetDescType(ev);
- mutableDesc->fODDescTypeValid = TRUE;
- }
-
- descriptorType = fODDescType;
- }
- else
- descriptorType = fPlatformDesc.descriptorType;
-
- return descriptorType;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::SetDescriptorType
- //----------------------------------------------------------------------------------------
-
- void FW_CDesc::SetDescriptorType(ODDescType newType)
- {
- if (fODDesc && FW_kPlatformDataIsStale)
- {
- FW_SOMEnvironment ev;
- fODDesc->SetDescType(ev, newType);
- fODDescType = newType;
- fODDescTypeValid = TRUE;
- }
- else
- {
- fPlatformDesc.descriptorType = newType;
- PrivPlatformDescChanged();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::PlatformDataHandle
- //----------------------------------------------------------------------------------------
-
- FW_PlatformHandle FW_CDesc::PlatformDataHandle() const
- {
- PrivUpdatePlatformDescIfStale();
- return (fPlatformDesc.dataHandle);
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::GetDataByPtr
- //----------------------------------------------------------------------------------------
-
- void FW_CDesc::GetDataByPtr(ODDescType dataType,
- void* dataPtr,
- Size* dataSize,
- Size maxSize,
- AEKeyword key) const
- {
- FW_CDesc coercedDesc;
- FW_Boolean copyFromOriginal = TRUE;
-
- if (key == keyNoKey)
- {
- if (dataType != typeWildCard && DescriptorType() != dataType)
- {
- Coerce(dataType, coercedDesc);
- copyFromOriginal = FALSE;
- }
- }
- else
- {
- GetDataByDesc(coercedDesc, key);
- copyFromOriginal = FALSE;
- }
-
- FW_PlatformHandle dataHandle = copyFromOriginal ? PlatformDataHandle()
- : coercedDesc.PlatformDataHandle();
- unsigned long actualSize = FW_CMemoryManager::GetSystemHandleSize(dataHandle);
-
- if (actualSize > maxSize)
- FW_FailOnError(memFullErr);
- else
- {
- FW_CAcquireLockedSystemHandle lock(dataHandle);
- FW_CMemoryManager::CopyMemory(*dataHandle, dataPtr, actualSize);
- if (dataSize)
- *dataSize = actualSize;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::PutDataByPtr
- //----------------------------------------------------------------------------------------
-
- void FW_CDesc::PutDataByPtr(ODDescType dataType,
- const void* dataPtr,
- Size dataSize,
- AEKeyword dataKey)
- {
- if (dataKey == keyNoKey)
- {
- if (IsNullDescriptor())
- CreateSimple(dataType, dataPtr, dataSize);
- else
- {
- if (!IsList())
- CoerceInPlace(typeAEList);
- FW_FailOnError(::AEPutPtr(*this, 0, dataType, dataPtr, dataSize));
- }
- }
- else
- {
- if (IsNullDescriptor())
- CreateRecord();
- FW_FailOnError(::AEPutKeyPtr(*this, dataKey, dataType, dataPtr, dataSize));
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::GetDataByDesc
- //----------------------------------------------------------------------------------------
-
- void FW_CDesc::GetDataByDesc(FW_CDesc& desc,
- AEKeyword key,
- ODDescType desiredType) const
- {
- FW_ASSERT(desc.IsNullDescriptor());
- FW_FailOnError(::AEGetKeyDesc(*this, key, desiredType, desc));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::PutDataByDesc
- //----------------------------------------------------------------------------------------
-
- void FW_CDesc::PutDataByDesc(const FW_CDesc& desc, AEKeyword key)
- {
- if (key == keyNoKey)
- {
- if (IsNullDescriptor())
- *this = desc;
- else
- {
- if (!IsList())
- CoerceInPlace(typeAEList);
- PutDescIntoList(desc);
- }
- }
- else
- {
- if (IsNullDescriptor())
- CreateRecord();
-
- FW_FailOnError(::AEPutKeyDesc(*this, key, desc));
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::GetItemCount
- //----------------------------------------------------------------------------------------
-
- long FW_CDesc::GetItemCount() const
- {
- long itemCount = 0;
- FW_FailOnError(::AECountItems(*this, &itemCount));
-
- return itemCount;
- }
- //----------------------------------------------------------------------------------------
- // FW_CDesc::GetDescFromList
- //----------------------------------------------------------------------------------------
-
- void FW_CDesc::GetDescFromList(long index,
- FW_CDesc& retrievedDesc,
- ODDescType desiredType) const
- {
- AEKeyword unusedKeyword;
- GetDescFromList(index, unusedKeyword, retrievedDesc, desiredType);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::GetDescFromList
- //----------------------------------------------------------------------------------------
-
- void FW_CDesc::GetDescFromList(long index,
- AEKeyword& descKey,
- FW_CDesc& retrievedDesc,
- ODDescType desiredType) const
- {
- FW_ASSERT(retrievedDesc.IsNullDescriptor());
-
- if (index == 1 && !IsList())
- {
- retrievedDesc = *this;
- }
- else // Note: indexes are 1-based
- FW_FailOnError(::AEGetNthDesc(*this, index, desiredType, &descKey, retrievedDesc));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::PutDescIntoList
- //----------------------------------------------------------------------------------------
-
- void FW_CDesc::PutDescIntoList(const FW_CDesc& desc, long index)
- {
- FW_FailOnError(::AEPutDesc(*this, index, desc));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::HasDataKey
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CDesc::HasDataKey(AEKeyword key) const
- {
- ODDescType typeCode;
- long actualSize;
-
- return (::AEGetParamPtr(*this, key, typeWildCard, &typeCode, NULL, 0, &actualSize) == FW_xNoError);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::GetDataInfoByKey
- //----------------------------------------------------------------------------------------
-
- void FW_CDesc::GetDataInfoByKey(AEKeyword key,
- ODDescType& typeCode,
- Size& dataSize) const
- {
- FW_FailOnError(::AESizeOfKeyDesc(*this, key, &typeCode, &dataSize));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::DeleteItemByIndex
- //----------------------------------------------------------------------------------------
-
- void FW_CDesc::DeleteItemByIndex(long index)
- {
- FW_ASSERT(IsList());
-
- FW_FailOnError(::AEDeleteItem(*this, index));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::DeleteItemByKey
- //----------------------------------------------------------------------------------------
-
- void FW_CDesc::DeleteItemByKey(ODDescType key)
- {
- FW_ASSERT(IsList());
-
- FW_FailOnError(::AEDeleteKeyDesc(*this, key));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::GetEnumeratedType
- //----------------------------------------------------------------------------------------
-
- ODDescType FW_CDesc::GetEnumeratedType(AEKeyword key) const
- {
- ODDescType value;
-
- GetDataByPtr(typeEnumerated, &value, NULL, sizeof(ODDescType), key);
- return value;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::PutEnumeratedType
- //----------------------------------------------------------------------------------------
-
- void FW_CDesc::PutEnumeratedType(ODDescType value, AEKeyword key)
- {
- PutDataByPtr(typeEnumerated, &value, sizeof(ODDescType), key);
- }
- //----------------------------------------------------------------------------------------
- // FW_CDesc::GetAbsoluteOrdinal
- //----------------------------------------------------------------------------------------
-
- ODDescType FW_CDesc::GetAbsoluteOrdinal(AEKeyword key) const
- {
- ODDescType value;
-
- GetDataByPtr(typeAbsoluteOrdinal, &value, NULL, sizeof(ODDescType), key);
- return value;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::PutAbsoluteOrdinal
- //----------------------------------------------------------------------------------------
-
- void FW_CDesc::PutAbsoluteOrdinal(ODDescType value, AEKeyword key)
- {
- PutDataByPtr(typeAbsoluteOrdinal, &value, sizeof(ODDescType), key);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::GetType
- //----------------------------------------------------------------------------------------
-
- ODDescType FW_CDesc::GetType(AEKeyword key) const
- {
- ODDescType value;
-
- GetDataByPtr(typeType, &value, NULL, sizeof(ODDescType), key);
- return value;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::PutType
- //----------------------------------------------------------------------------------------
-
- void FW_CDesc::PutType(ODDescType value, AEKeyword key)
- {
- PutDataByPtr(typeType, &value, sizeof(ODDescType), key);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::GetBoolean
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CDesc::GetBoolean(AEKeyword key) const
- {
- FW_Boolean value;
-
- GetDataByPtr(typeBoolean, &value, NULL, sizeof(FW_Boolean), key);
- return value;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::PutBoolean
- //----------------------------------------------------------------------------------------
-
- void FW_CDesc::PutBoolean(FW_Boolean value, AEKeyword key)
- {
- PutDataByPtr(typeBoolean, &value, sizeof(FW_Boolean), key);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::GetLongInteger
- //----------------------------------------------------------------------------------------
-
- long FW_CDesc::GetLongInteger(AEKeyword key) const
- {
- long value;
-
- GetDataByPtr(typeLongInteger, &value, NULL, sizeof(long), key);
- return value;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::PutLongInteger
- //----------------------------------------------------------------------------------------
-
- void FW_CDesc::PutLongInteger(long value, AEKeyword key)
- {
- PutDataByPtr(typeLongInteger, &value, sizeof(long), key);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::GetShortInteger
- //----------------------------------------------------------------------------------------
-
- short FW_CDesc::GetShortInteger(AEKeyword key) const
- {
- short value;
-
- GetDataByPtr(typeShortInteger, &value, NULL, sizeof(short), key);
- return value;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::GetString
- //----------------------------------------------------------------------------------------
-
- void FW_CDesc::GetString(FW_CString& string, AEKeyword key) const
- {
- FW_CDesc secondaryDesc;
- FW_Boolean copyFromThis = TRUE;
-
- if (key != keyNoKey)
- {
- GetDataByDesc(secondaryDesc, key, typeChar);
- copyFromThis = FALSE;
- }
- else if (DescriptorType() != typeChar)
- {
- Coerce(typeChar, secondaryDesc);
- copyFromThis = FALSE;
- }
-
- FW_PlatformHandle dataHandle = copyFromThis ? PlatformDataHandle() : secondaryDesc.PlatformDataHandle();
-
- FW_CAcquireLockedSystemHandle lock(dataHandle);
- string.ReplaceAll(*dataHandle, FW_CMemoryManager::GetSystemHandleSize(dataHandle));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::PutString
- //----------------------------------------------------------------------------------------
-
- void FW_CDesc::PutString(const FW_CString& string, AEKeyword key)
- {
- PutDataByPtr(typeChar, string.RevealBuffer(), string.GetByteLength(), key);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::GetColor
- //----------------------------------------------------------------------------------------
-
- void FW_CDesc::GetColor(FW_CColor& color, AEKeyword key) const
- {
- RGBColor platformColor;
-
- GetDataByPtr(typeRGBColor, &platformColor, NULL, sizeof(RGBColor), key);
- color = platformColor;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::PutColor
- //----------------------------------------------------------------------------------------
-
- void FW_CDesc::PutColor(const FW_CColor& color, AEKeyword key)
- {
- RGBColor platformColor = color;
- PutDataByPtr(typeRGBColor, &platformColor, sizeof(RGBColor), key);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::GetPoint
- //----------------------------------------------------------------------------------------
-
- void FW_CDesc::GetPoint(FW_CPoint& point, AEKeyword key) const
- {
- FW_PlatformPoint platformPoint;
-
- GetDataByPtr(typeQDPoint, &platformPoint, NULL, sizeof(FW_PlatformPoint), key);
- point = platformPoint;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::PutPoint
- //----------------------------------------------------------------------------------------
-
- void FW_CDesc::PutPoint(const FW_CPoint& point, AEKeyword key)
- {
- FW_PlatformPoint platformPoint = point.AsPlatformPoint();
-
- PutDataByPtr(typeQDPoint, &platformPoint, sizeof(FW_PlatformPoint), key);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::GetRect
- //----------------------------------------------------------------------------------------
-
- void FW_CDesc::GetRect(FW_CRect& rect, AEKeyword key) const
- {
- FW_PlatformRect platformRect;
-
- GetDataByPtr(typeQDRectangle, &platformRect, NULL, sizeof(FW_PlatformRect), key);
- rect = platformRect;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::PutRect
- //----------------------------------------------------------------------------------------
-
- void FW_CDesc::PutRect(const FW_CRect& rect, AEKeyword key)
- {
- FW_PlatformRect platformRect = rect.AsPlatformRect();
- PutDataByPtr(typeQDRectangle, &platformRect, sizeof(FW_PlatformRect), key);
- }
-
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::Compare(const FW_CDesc& other, const ODDescType operation)
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CDesc::Compare(ODDescType operation, const FW_CDesc& other) const
- {
- if (this == &other) // compare to self
- {
- switch (operation)
- {
- case kAEEquals:
- case kAEGreaterThanEquals:
- case kAELessThanEquals:
- case kAEBeginsWith:
- case kAEEndsWith:
- case kAEContains:
- return TRUE;
- break;
-
- case kASNotEqual:
- case kAEGreaterThan:
- case kAELessThan:
- return FALSE;
- break;
-
- default:
- FW_Failure(errAEEventNotHandled);
- break;
- }
- }
-
- FW_CDesc secondaryDesc;
- const FW_CDesc* lhDesc = this;
- const FW_CDesc* rhDesc = &other;
- FW_Boolean result = TRUE;
-
- if (DescriptorType() != other.DescriptorType()) // coerce to common type
- {
- if (AECoerceDesc(other, DescriptorType(), secondaryDesc) == noErr)
- rhDesc = &secondaryDesc;
- else if (AECoerceDesc(*this, other.DescriptorType(), secondaryDesc) == noErr)
- lhDesc = &secondaryDesc;
- else
- return FALSE;
- }
-
- if (lhDesc->IsList())
- {
- result = PrivCompareLists(operation, *lhDesc, *rhDesc);
- }
- else
- {
- FW_Handled handled = FW_CDescComparisonCallbacks::InvokeHandler(operation, *lhDesc, *rhDesc, result);
- if (handled != FW_kHandled)
- {
- switch (lhDesc->DescriptorType())
- {
- long lhLong;
- long rhLong;
-
- case typeEnumerated:
- lhLong = (long)lhDesc->GetEnumeratedType();
- rhLong = (long)rhDesc->GetEnumeratedType();
- result = PrivCompareLongs(operation, lhLong, rhLong);
- break;
-
- case typeType:
- lhLong = (long)lhDesc->GetType();
- rhLong = (long)rhDesc->GetType();
- result = PrivCompareLongs(operation, lhLong, rhLong);
- break;
-
- case typeBoolean:
- lhLong = (long)lhDesc->GetBoolean();
- rhLong = (long)rhDesc->GetBoolean();
- result = PrivCompareLongs(operation, lhLong, rhLong);
- break;
-
- case typeLongInteger:
- case typeShortInteger:
- lhLong = lhDesc->GetLongInteger();
- rhLong = rhDesc->GetLongInteger();
- result = PrivCompareLongs(operation, lhLong, rhLong);
- break;
-
- case typeChar:
- {
- FW_CString lhString;
- FW_CString rhString;
- lhDesc->GetString(lhString);
- rhDesc->GetString(rhString);
- result = PrivCompareStrings(operation, lhString, rhString);
- }
- break;
-
- case typeRGBColor:
- {
- FW_CColor lhColor;
- FW_CColor rhColor;
- lhDesc->GetColor(lhColor);
- rhDesc->GetColor(rhColor);
- result = PrivCompareColors(operation, lhColor, rhColor);
- }
- break;
-
- default:
- result = PrivCompareData(operation, *lhDesc, *rhDesc);
- break;
- }
- }
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::operator=(const FW_CDesc& other)
- //----------------------------------------------------------------------------------------
-
- FW_CDesc& FW_CDesc::operator=(const FW_CDesc& other)
- {
- if (this == &other)
- return *this;
-
- PrivFlushData();
- FW_FailOnError(::AEDuplicateDesc(other, *this));
-
- return (*this);
- }
-
- //----------------------------------------------------------------------------------------
- // AEDesc& FW_CDesc::operator const AEDesc&
- //----------------------------------------------------------------------------------------
-
- FW_CDesc::operator const AEDesc&() const
- {
- PrivUpdatePlatformDescIfStale();
- return fPlatformDesc;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::operator AEDesc* const
- //----------------------------------------------------------------------------------------
-
- FW_CDesc::operator AEDesc*() const
- {
- PrivUpdatePlatformDescIfStale();
- PrivPlatformDescChanged(); // non-const access might change data
- return PrivGetPlatformDescPtr();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::operator const AEDesc*
- //----------------------------------------------------------------------------------------
-
- FW_CDesc::operator const AEDesc*() const
- {
- PrivUpdatePlatformDescIfStale();
- return (AEDesc*)&fPlatformDesc;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::operator ODDesc*
- //----------------------------------------------------------------------------------------
-
- FW_CDesc::operator ODDesc*() const
- {
- PrivUpdateODDescIfStale();
- PrivODDescChanged();
- return fODDesc;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::operator ODObjectSpec*
- //----------------------------------------------------------------------------------------
-
- FW_CDesc::operator ODObjectSpec*() const
- {
- PrivUpdateODDescIfStale();
- PrivODDescChanged();
- return (ODObjectSpec*)fODDesc;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::operator ODOSLToken*
- //----------------------------------------------------------------------------------------
-
- FW_CDesc::operator ODOSLToken*() const
- {
- PrivUpdateODDescIfStale();
- PrivODDescChanged();
- return (ODOSLToken*)fODDesc;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::operator ODAddressDesc*
- //----------------------------------------------------------------------------------------
-
- FW_CDesc::operator ODAddressDesc*() const
- {
- PrivUpdateODDescIfStale();
- PrivODDescChanged();
- return (ODAddressDesc*)fODDesc;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::operator ODAddressDesc**
- //----------------------------------------------------------------------------------------
-
- FW_CDesc::operator ODAddressDesc**()
- {
- PrivDispose();
- PrivODDescChanged();
- return (ODAddressDesc**)&fODDesc;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::PrivCompareLists
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CDesc::PrivCompareLists(ODDescType operation,
- const FW_CDesc& lhDesc,
- const FW_CDesc& rhDesc) const
- {
- FW_Boolean result = TRUE;
- FW_Boolean resultConclusive = FALSE;
-
- long maxToCompare;
- long lhIndex = 1;
-
- switch(operation)
- {
- case kAEEquals:
- maxToCompare = lhDesc.GetItemCount();
- if (maxToCompare != rhDesc.GetItemCount())
- {
- result = FALSE;
- resultConclusive = TRUE;
- }
- break;
-
- case kASNotEqual:
- maxToCompare = lhDesc.GetItemCount();
- if (maxToCompare != rhDesc.GetItemCount())
- {
- result = TRUE;
- resultConclusive = TRUE;
- }
- break;
-
- case kAEBeginsWith:
- maxToCompare = rhDesc.GetItemCount();
- if (maxToCompare > lhDesc.GetItemCount())
- {
- result = FALSE;
- resultConclusive = TRUE;
- }
- break;
-
- case kAEEndsWith:
- maxToCompare = rhDesc.GetItemCount();
- if (maxToCompare > lhDesc.GetItemCount())
- {
- result = FALSE;
- resultConclusive = TRUE;
- }
- else
- lhIndex = lhDesc.GetItemCount() - maxToCompare + 1;
- break;
-
- default:
- result = FALSE;
- resultConclusive = TRUE;
- break;
- }
-
- if (!resultConclusive)
- {
- FW_CDesc lhTestDesc;
- FW_CDesc rhTestDesc;
-
- for (long rhIndex = 1; rhIndex <= maxToCompare && result; lhIndex++, rhIndex++)
- {
- lhDesc.GetDescFromList(lhIndex, lhTestDesc);
- rhDesc.GetDescFromList(rhIndex, rhTestDesc);
-
- result = lhTestDesc.Compare(operation, rhTestDesc);
-
- lhTestDesc.Clear();
- rhTestDesc.Clear();
- }
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::PrivCompareLongs
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CDesc::PrivCompareLongs(ODDescType operation,
- long lhs,
- long rhs) const
- {
- FW_Boolean result;
-
- switch (operation)
- {
- case kAEEquals:
- result = (lhs == rhs);
- break;
-
- case kASNotEqual:
- result = (lhs != rhs);
- break;
-
- case kAEGreaterThanEquals:
- result = (lhs >= rhs);
- break;
-
- case kAEGreaterThan:
- result = (lhs > rhs);
- break;
-
- case kAELessThanEquals:
- result = (lhs <= rhs);
- break;
-
- case kAELessThan:
- result = (lhs < rhs);
- break;
-
- default:
- FW_Failure(errAEEventNotHandled);
- break;
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::PrivCompareStrings
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CDesc::PrivCompareStrings(ODDescType operation,
- const FW_CString& lhs,
- const FW_CString& rhs) const
- {
- FW_Boolean result;
-
- switch (operation)
- {
- FW_BytePosition foundPosition;
-
- case kAEEquals:
- result = (lhs == rhs);
- break;
-
- case kASNotEqual:
- result = (lhs != rhs);
- break;
-
- case kAEGreaterThan:
- result = (lhs > rhs);
- break;
-
- case kAEGreaterThanEquals:
- result = (lhs >= rhs);
- break;
-
- case kAELessThan:
- result = (lhs < rhs);
- break;
-
- case kAELessThanEquals:
- result = (lhs <= rhs);
- break;
-
- case kAEBeginsWith:
- lhs.FindSubString(rhs, foundPosition);
- result = (foundPosition == 1);
- break;
-
- case kAEEndsWith:
- lhs.FindSubString(rhs, foundPosition);
- result = ((foundPosition > 0) &&
- (foundPosition == (lhs.GetByteLength() - rhs.GetByteLength())));
- break;
-
- case kAEContains:
- lhs.FindSubString(rhs, foundPosition);
- result = (foundPosition > 0);
- break;
-
- default:
- FW_Failure(errAEEventNotHandled);
- break;
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::PrivCompareColors
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CDesc::PrivCompareColors(ODDescType operation,
- const FW_CColor& lhs,
- const FW_CColor& rhs) const
- {
- FW_Boolean result;
-
- switch (operation)
- {
- case kAEEquals:
- result = (lhs == rhs);
- break;
-
- case kASNotEqual:
- result = (lhs != rhs);
- break;
-
- case kAEGreaterThan:
- result = lhs.IsLighterThan(rhs);
- break;
-
- case kAEGreaterThanEquals:
- result = (lhs == rhs || lhs.IsLighterThan(rhs));
- break;
-
- case kAELessThan:
- result = lhs.IsDarkerThan(rhs);
- break;
-
- case kAELessThanEquals:
- result = (lhs == rhs || lhs.IsDarkerThan(rhs));
- break;
-
- default:
- FW_Failure(errAEEventNotHandled);
- break;
- }
- return result;
- }
- //----------------------------------------------------------------------------------------
- // FW_CDesc::PrivCompareData
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CDesc::PrivCompareData(ODDescType operation,
- const FW_CDesc& lhDesc,
- const FW_CDesc& rhDesc) const
- {
-
- long lhDataSize = FW_CMemoryManager::GetSystemHandleSize(lhDesc.PlatformDataHandle());
- long rhDataSize = FW_CMemoryManager::GetSystemHandleSize(rhDesc.PlatformDataHandle());
-
- FW_CAcquireLockedSystemHandle lhLock(lhDesc.PlatformDataHandle());
- FW_CAcquireLockedSystemHandle rhLock(rhDesc.PlatformDataHandle());
-
- const char* lhData = *lhDesc.PlatformDataHandle();
- const char* rhData = *rhDesc.PlatformDataHandle();
-
- long bytesToCompare;
-
- FW_Boolean result = TRUE;
- FW_Boolean resultConclusive = FALSE;
-
- switch (operation)
- {
- case kAEEquals:
- bytesToCompare = lhDataSize;
- if (bytesToCompare != rhDataSize)
- {
- result = FALSE;
- resultConclusive = TRUE;
- }
- break;
-
- case kASNotEqual:
- bytesToCompare = lhDataSize;
- if (bytesToCompare != rhDataSize)
- {
- result = TRUE;
- resultConclusive = TRUE;
- }
- break;
-
- case kAEBeginsWith:
- bytesToCompare = rhDataSize;
- if (bytesToCompare > lhDataSize)
- {
- result = FALSE;
- resultConclusive = TRUE;
- }
- break;
-
- case kAEEndsWith:
- bytesToCompare = rhDataSize;
- if (bytesToCompare > lhDataSize)
- {
- result = FALSE;
- resultConclusive = TRUE;
- }
- else
- lhData = (*lhDesc.PlatformDataHandle()) + lhDataSize - bytesToCompare;
- break;
-
- default:
- result = FALSE;
- resultConclusive = FALSE;
- break;
- }
-
- while (bytesToCompare && !resultConclusive)
- {
- switch (operation)
- {
- case kAEEquals:
- case kAEBeginsWith:
- case kAEEndsWith:
- result = (*lhData == *rhData);
- if (!result)
- resultConclusive = TRUE;
- break;
-
- case kASNotEqual:
- result = (*lhData != *rhData);
- if (result)
- resultConclusive = TRUE;
- break;
-
- case kAEGreaterThan:
- result = *lhData > *rhData;
- if (!result)
- resultConclusive = TRUE;
- break;
-
- case kAEGreaterThanEquals:
- result = *lhData >= *rhData;
- if (!result)
- resultConclusive = TRUE;
- break;
-
- case kAELessThan:
- result = *lhData < *rhData;
- if (!result)
- resultConclusive = TRUE;
- break;
-
- case kAELessThanEquals:
- result = *lhData <= *rhData;
- if (!result)
- resultConclusive = TRUE;
- break;
-
- default:
- result = FALSE;
- resultConclusive = TRUE;
- }
-
- lhData++;
- rhData++;
- bytesToCompare--;
- }
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::PrivFlushPlatformData
- //----------------------------------------------------------------------------------------
-
- void FW_CDesc::PrivFlushPlatformData() const
- {
- FW_CDesc& mutableDesc = (FW_CDesc&)*this;
-
- if (fPlatformDesc.dataHandle != NULL)
- {
- if (fRealPlatformDesc)
- ::AEDisposeDesc(&mutableDesc.fPlatformDesc);
- else
- {
- ::DisposeHandle(fPlatformDesc.dataHandle);
- mutableDesc.fPlatformDesc.dataHandle = NULL;
- }
- }
-
- mutableDesc.fPlatformDesc.descriptorType = typeNull;
- mutableDesc.fDataState = FW_kODDataIsStale;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::PrivFlushODData
- //----------------------------------------------------------------------------------------
-
- void FW_CDesc::PrivFlushODData() const
- {
- if (fODDesc)
- {
- FW_CByteArray byteArray;
- FW_SOMEnvironment ev;
-
- byteArray.Set(NULL, 0);
- fODDesc->SetRawData(ev, byteArray);
- fODDesc->SetDescType(ev, typeNull);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::PrivFlushData
- //----------------------------------------------------------------------------------------
-
- void FW_CDesc::PrivFlushData()
- {
- PrivFlushPlatformData();
- PrivFlushODData();
-
- fDataState = FW_kPlatformMatchesOD;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::PrivDispose
- //----------------------------------------------------------------------------------------
-
- void FW_CDesc::PrivDispose()
- {
- if (fODDesc)
- {
- if (fOwnODDesc)
- delete fODDesc;
- else
- PrivUpdateODDescIfStale();
-
- fODDesc = NULL;
- fOwnODDesc = TRUE;
- }
-
- fDataState = FW_kPlatformMatchesOD;
-
- PrivFlushPlatformData();
-
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::PrivUpdatePlatformDesc
- //----------------------------------------------------------------------------------------
-
- void FW_CDesc::PrivUpdatePlatformDesc() const
- {
- FW_ASSERT(fODDesc);
-
- FW_CDesc* mutableDesc = (FW_CDesc*)this;
- FW_SOMEnvironment ev;
- ODDescType odDescType = fODDesc->GetDescType(ev);
-
- mutableDesc->fDataState = FW_kSynchronizing;
-
- PrivFlushPlatformData();
-
- if (odDescType != typeNull)
- {
- ODByteArray byteArray;
- byteArray = fODDesc->GetRawData(ev);
- // use a temporary type to prevent redundant list/record
- // header info from being generated when AECreateDesc is called
- mutableDesc->CreateSimple('greg', byteArray._buffer, byteArray._length);
- mutableDesc->fPlatformDesc.descriptorType = odDescType;
- }
-
- mutableDesc->fDataState = FW_kPlatformMatchesOD;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::PrivUpdateODDesc
- //----------------------------------------------------------------------------------------
-
- void FW_CDesc::PrivUpdateODDesc() const
- {
-
- FW_CByteArray byteArray;
- FW_CDesc* mutableDesc = (FW_CDesc*)this;
- FW_SOMEnvironment ev;
-
- mutableDesc->fDataState = FW_kSynchronizing;
-
- PrivFlushODData();
-
- if (!fODDesc)
- mutableDesc->fODDesc = PrivCreateODDesc(ev);
-
- if (fPlatformDesc.descriptorType != typeNull)
- fODDesc->SetDescType(ev, fPlatformDesc.descriptorType);
-
- if (fPlatformDesc.dataHandle != NULL)
- {
- FW_CAcquireLockedSystemHandle lock(fPlatformDesc.dataHandle);
- byteArray.Set(*fPlatformDesc.dataHandle, FW_CMemoryManager::GetSystemHandleSize(fPlatformDesc.dataHandle));
- fODDesc->SetRawData(ev, byteArray);
- }
- else
- fODDesc->SetRawData(ev, byteArray);
-
- mutableDesc->fODDescType = fPlatformDesc.descriptorType;
- mutableDesc->fODDescTypeValid = TRUE;
- mutableDesc->fDataState = FW_kPlatformMatchesOD;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDesc::PrivCreateODDesc
- //----------------------------------------------------------------------------------------
-
- ODDesc* FW_CDesc::PrivCreateODDesc(Environment* ev) const
- {
- ODDesc* odDesc = new ODDesc;
- odDesc->InitODDesc(ev);
-
- return odDesc;
- }
-